layui.define(['layer','jquery','form'], function (exports) {
    var $ = layui.jquery;
    var layer=layui.layer;
    var form = layui.form();

    form.on('checkbox(check)', function(data){
        if(data.elem.checked){
            $("input[name='checkbox']").prop("checked", true);
        }else{
            $("input[name='checkbox']").prop("checked", false);
        }  
        form.render('checkbox');      
    }); 

    $("#btn_add").click(function(){
        add_dict();
     });
     
     function add_dict() {
        //iframe层
        layer.open({
            type: 2,
            title: '添加报修类型',
            shadeClose: false,
            shade: 0.8,
            area: ['580px', '450px'],
            full:true,
            content: '?t=repair_edit', //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
    }
    $("#btn_del").click(function(){
        var m_val="";
        $("[name='checkbox']:checked").each(function(i, obj) {
			m_val+=$(this).val()+",";
		});
        if(m_val.lastIndexOf(",")>0){
            m_val=m_val.substring(0,m_val.length-1) ;
        }
        if(m_val.length>0){ 
            layer.confirm('确定删除？',function(index){
                $.post("/srv/sdo.php", {tpl:"del_repair_typelist",id:m_val}, function (d, e) {
                    if(d=="ok"){
                        location.reload();
                    }
                });
            });
        }else{
            layer.msg('没有选择数据');
        } 
    });
    $('button[data-opt=update]').click(function(){
        var t_id=$(this).data('id');
        edit_grade(t_id);
    });
    function edit_grade(id) {
        //iframe层
        layer.open({
            type: 2,
            title: '报修类型',
            shadeClose: false,
            shade: 0.8,
            area: ['580px', '450px'],
            full:true,
            content: '?t=repair_edit&id='+id, //iframe的url
            end: function(){ 
                location.reload();
            }
        }); 
    }
    $('button[data-opt=del]').click(function(){
        var id=$(this).data('id');
        layer.confirm('确定删除？',function(index){
            $.post("./srv/sdo.php", {tpl:"del_repair_type",id:id}, function (d, e) {
                if(d=="ok"){
                    location.reload();
                }
            });
        });
    });
    $("#btn_ref").click(function(){
        location.reload();
    });
    $("#btn_search").bind("click",function(){   
        var nm=$("#d_name").val();
        location.href="?t=repair_type&name="+nm;
   });  
    
    exports('repair_type', {});
});